package 力扣;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-08-15
 * Time: 23:05
 */
class MyCircularDeque {
    int[] q;
    int left = 0;
    int right = 0;

    public MyCircularDeque(int k) {
        q = new int[k+1];
    }

    private int get(int x){
        return (x + q.length) % q.length;
    }

    public boolean insertFront(int value) {
        if(isFull()){
            return false;
        }
        left = get(left-1);
        q[left] = value;
        return true;
    }

    public boolean insertLast(int value) {
        if(isFull()){
            return false;
        }
        q[right] = value;
        right = get(right+1);
        return true;
    }

    public boolean deleteFront() {
        if(isEmpty()){
            return false;
        }
        left = get(left+1);
        return true;
    }

    public boolean deleteLast() {
        if(isEmpty()){
            return false;
        }
        right = get(right-1);
        return true;
    }

    public int getFront() {
        if(isEmpty()){
            return -1;
        }
        return q[left];
    }

    public int getRear() {
        if(isEmpty()){
            return -1;
        }
        return q[get(right-1)];
    }

    public boolean isEmpty() {
        return left == right;
    }

    public boolean isFull() {
        return right == get(left-1);
    }
}

public class design_circular_deque {
    public static void main(String[] args) {
        MyCircularDeque myCircularDeque = new MyCircularDeque(2);
    }
}
